package social.hub;

import social.hub.api.facebook.FacebookConstants;
import social.hub.api.google.buzz.BuzzConstants;
import social.hub.api.google.orkut.OrkutConstants;
import social.hub.api.linkedin.LinkedInConstants;
import social.hub.api.twitter.TwitterConstants;
import social.hub.oauth.OAuthConfig;
import social.hub.oauth.OAuthVersion;

public class SocialConfigFactory {

	public OAuthConfig getBuzzConfig(String apiKey, String apiSecret, String callbackUrl) {

		OAuthConfig config = new OAuthConfig();

		config.setRequestTokenUrl(BuzzConstants.OAUTH_REQUEST_TOKEN_URL);
		config.setAccessTokenUrl(BuzzConstants.OAUTH_ACCESS_TOKEN_URL);
		config.setAuthorizeUrl(BuzzConstants.OAUTH_AUTHORIZE_URL);
		config.setScope(BuzzConstants.OAUTH_SCOPE);
		config.setVersion(OAuthVersion.V_1a);

		config.setApiKey(apiKey);
		config.setApiSecret(apiSecret);
		config.setCallbackUrl(callbackUrl);

		return config;

	}

	public OAuthConfig getFacebookConfig(String apiId, String apiKey, String apiSecret, String callbackUrl,
			String... scopes) {

		OAuthConfig config = new OAuthConfig();

		config.setAccessTokenUrl(FacebookConstants.OAUTH_ACCESS_TOKEN_URL);
		config.setAuthorizeUrl(FacebookConstants.OAUTH_AUTHORIZE_URL);
		config.setVersion(OAuthVersion.V_2);

		StringBuilder scope = new StringBuilder();

		for (String s : scopes) {
			scope.append(s).append(";");
		}

		scope.delete(scope.length() - 1, scope.length());

		config.setAppId(apiId);
		config.setApiKey(apiKey);
		config.setApiSecret(apiSecret);
		config.setCallbackUrl(callbackUrl);
		config.setScope(scope.toString());

		return config;

	}

	public OAuthConfig getOrkutConfig(String apiKey, String apiSecret, String callbackUrl) {

		OAuthConfig config = new OAuthConfig();

		config.setRequestTokenUrl(OrkutConstants.OAUTH_REQUEST_TOKEN_URL);
		config.setAccessTokenUrl(OrkutConstants.OAUTH_ACCESS_TOKEN_URL);
		config.setAuthorizeUrl(OrkutConstants.OAUTH_AUTHORIZE_URL);
		config.setScope(OrkutConstants.OAUTH_SCOPE_FOR_RPC);
		config.setVersion(OAuthVersion.V_1a);

		config.setApiKey(apiKey);
		config.setApiSecret(apiSecret);
		config.setCallbackUrl(callbackUrl);

		return config;

	}

	public OAuthConfig getTwitterConfig(String apiKey, String apiSecret, String callbackUrl) {

		OAuthConfig config = new OAuthConfig();

		config.setRequestTokenUrl(TwitterConstants.OAUTH_REQUEST_TOKEN_URL);
		config.setAccessTokenUrl(TwitterConstants.OAUTH_ACCESS_TOKEN_URL);
		config.setAuthorizeUrl(TwitterConstants.OAUTH_AUTHORIZE_URL);
		config.setVersion(OAuthVersion.V_1);

		config.setApiKey(apiKey);
		config.setApiSecret(apiSecret);
		config.setCallbackUrl(callbackUrl);

		return config;

	}

	public OAuthConfig getLinkedInConfig(String apiKey, String apiSecret, String callbackUrl) {

		OAuthConfig config = new OAuthConfig();

		config.setRequestTokenUrl(LinkedInConstants.OAUTH_REQUEST_TOKEN_URL);
		config.setAccessTokenUrl(LinkedInConstants.OAUTH_ACCESS_TOKEN_URL);
		config.setAuthorizeUrl(LinkedInConstants.OAUTH_AUTHORIZE_URL);
		config.setVersion(OAuthVersion.V_1);

		config.setApiKey(apiKey);
		config.setApiSecret(apiSecret);
		config.setCallbackUrl(callbackUrl);

		return config;

	}

}
